package snackserver

class RecvController {

    def index = { }
    
    def sendScore = {
        def name = params.username
        def score = params.score
        def model = params.model
        if(name==null || score==null || model==null){
            returnError()
        }else{
            def m = Mode.findByName(model)
            //TODO remove it in future
            def u = new User(name:name)
            u.addToRecord(new Record(mode:m,score:score))
            u.save()
            println "u=${u}"
            if(u==null)
                returnError()
            else
                returnSuccess()
        }
    }
    
    private void returnError(){
		render status: 400
	}
    private void returnSuccess(){
		render status: 200
	}

}
